﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace PermissionsManager.DAL
{
    public class DbContextFactory<TS> where TS:DbContext ,new ()
    {
        /// <summary>
        /// 得到唯一实例
        /// </summary>
        public static DbContext GetCurrentDbContext() {
            var dbContext = CallContext.GetData(typeof(TS).Name) as DbContext;
            if (dbContext!=null)
            {
                return dbContext;
            }
            dbContext = new TS();
            CallContext.SetData(typeof(TS).Name, dbContext);
            return dbContext;
        }
    }
}
